package com.example.moshudriver.model;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

import com.BeeFramework.model.BaseModel;
import com.BeeFramework.model.BeeCallback;
import com.example.moshudriver.protocol.ApiInterface;
import com.example.moshudriver.protocol.CONFIG;
import com.example.moshudriver.protocol.ENUM_USER_GENDER;
import com.example.moshudriver.protocol.LOCATION;
import com.example.moshudriver.protocol.USER;
import com.example.moshudriver.protocol.otherRequest;
import com.example.moshudriver.protocol.otherResponse;
import com.example.moshudriver.protocol.userbalanceRequest;
import com.example.moshudriver.protocol.userbalanceResponse;
import com.example.moshudriver.protocol.userchange_passwordRequest;
import com.example.moshudriver.protocol.userchange_passwordResponse;
import com.example.moshudriver.protocol.userchange_profileRequest;
import com.example.moshudriver.protocol.userchange_profileResponse;
import com.example.moshudriver.protocol.userinvite_codeRequest;
import com.example.moshudriver.protocol.userinvite_codeResponse;
import com.example.moshudriver.protocol.usersigninRequest;
import com.example.moshudriver.protocol.usersigninResponse;
import com.example.moshudriver.protocol.usersignupRequest;
import com.example.moshudriver.protocol.usersignupResponse;
import com.example.moshudriver.protocol.uservalidcodeRequest;
import com.example.moshudriver.protocol.uservalidcodeResponse;
import com.example.moshudriver.protocol.userverifycodeRequest;
import com.example.moshudriver.protocol.userverifycodeResponse;
import com.example.moshudriver.tools.APIErrorCode;
import com.example.moshudriver.tools.LocationManager;
import com.example.moshudriver.tools.O2OMobile;
import com.example.moshudriver.tools.O2OMobileAppConst;
import com.example.moshudriver.tools.SESSION;
import com.external.androidquery.callback.AjaxStatus;

public class UserModel extends BaseModel {
	private Context context;
	public String invite_code;
	public String text;//描述代理说明
	public String mContent;

	public UserModel(Context context) {
		super(context);
		this.context = context;

	}

	// 从服务器获取关于我们的数据
	public void aboutUs() {

		otherRequest request = new otherRequest();
		request.content = "content";
		BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() {
			@Override
			public void callback(String url, JSONObject jo, AjaxStatus status) {

				try {
					// 获得网络的json数据之后，的回调函数
					UserModel.this.callback(this, url, jo, status);
					if (null != jo) {
						otherResponse response = new otherResponse();
						response.fromJson(jo);
						if (response.succeed == 1) {
							mContent = response.content;
							// System.out.println("response.content:"+response.content);
							UserModel.this.OnMessageResponse(url, jo, status);
						} else {
							UserModel.this.callback(url, response.error_code,
									response.error_desc);
						}
					}

				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		};
		Map<String, String> params = new HashMap<String, String>();
		try {
			params.put("json", request.toJson().toString());
		} catch (JSONException e) {

		}
		// 参数(json类型)和接口USER_FIND_PWD
		cb.url(ApiInterface.COMMENT_ABOUTUS).type(JSONObject.class)
				.params(params);
		// 提交参数，并且访问服务器
		ajaxProgress(cb);

	}

	// 从服务器获取免责声明
	public void Declare() {
		userbalanceRequest request = new userbalanceRequest();
		request.content = "content";
		BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() {
			@Override
			public void callback(String url, JSONObject jo, AjaxStatus status) {

				try {
					// 获得网络的json数据之后，的回调函数
					UserModel.this.callback(this, url, jo, status);
					if (null != jo) {
						userbalanceResponse response = new userbalanceResponse();
						response.fromJson(jo);
						if (response.succeed == 1) {
							mContent = response.content;
							// System.out.println("response.content:"+response.content);
							UserModel.this.OnMessageResponse(url, jo, status);
						} else {
							UserModel.this.callback(url, response.error_code,
									response.error_desc);
						}
					}

				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		};
		Map<String, String> params = new HashMap<String, String>();
		try {
			params.put("json", request.toJson().toString());
		} catch (JSONException e) {

		}
		// 参数(json类型)和接口USER_FIND_PWD
		cb.url(ApiInterface.COMMENT_DISCLAIMER).type(JSONObject.class)
				.params(params);
		// 提交参数，并且访问服务器
		ajaxProgress(cb);

	}

	public void findPassWord(String mobile, String password) {

		usersigninRequest request = new usersigninRequest();
		request.password = password;
		request.mobile_phone = mobile;
		request.role = "2";
		BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() {
			@Override
			public void callback(String url, JSONObject jo, AjaxStatus status) {

				// 获得网络的json数据之后，的回调函数
				UserModel.this.callback(this, url, jo, status);
				try {// 回调到登录界面
					UserModel.this.OnMessageResponse(url, jo, status);
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		};
		Map<String, String> params = new HashMap<String, String>();
		try {
			params.put("json", request.toJson().toString());
		} catch (JSONException e) {

		}
		// 参数(json类型)和接口
		cb.url(ApiInterface.USER_FIND_PWD).type(JSONObject.class)
				.params(params);
		// 提交参数，并且访问服务器
		ajaxProgress(cb);

	}
	
	
	
	public void copartnerfindPassWord(String mobile, String password) {

		usersigninRequest request = new usersigninRequest();
		request.password = password;
		request.mobile_phone = mobile;
		request.role = "3";
		BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() {
			@Override
			public void callback(String url, JSONObject jo, AjaxStatus status) {

				// 获得网络的json数据之后，的回调函数
				UserModel.this.callback(this, url, jo, status);
				try {// 回调到登录界面
					UserModel.this.OnMessageResponse(url, jo, status);
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		};
		Map<String, String> params = new HashMap<String, String>();
		try {
			params.put("json", request.toJson().toString());
		} catch (JSONException e) {

		}
		// 参数(json类型)和接口
		cb.url(ApiInterface.USER_FIND_PWD).type(JSONObject.class)
				.params(params);
		// 提交参数，并且访问服务器
		ajaxProgress(cb);

	}
	/**
	 * 合伙人登录
	 * @param mobile
	 * @param password
	 */
	public void copartner_login(String mobile, String password) {

		usersigninRequest request = new usersigninRequest();
		request.mobile_phone = mobile;
		request.password = password;
		request.UUID = O2OMobile.getDeviceId(context);
		request.platform = "android";
		request.role = "3";
		request.ver = O2OMobileAppConst.VERSION_CODE;
		LOCATION location = new LOCATION();
		location.lat = LocationManager.getLatitude();
		location.lon = LocationManager.getLongitude();
		request.location = location;
		BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() {
			@Override
			public void callback(String url, JSONObject jo, AjaxStatus status) {

				// 获得网络的json数据之后，的回调函数
				try {
					UserModel.this.callback(this, url, jo, status);

					if (null != jo) {
						// 用户成功登录之后，返回的数据，转换为usersigninResponse对象
						usersigninResponse usersigninResponse = new usersigninResponse();
						usersigninResponse.fromJson(jo);
						if (usersigninResponse.succeed == 1) {
							// 保存返回来的数据
							USER user = usersigninResponse.user;
							CONFIG config = usersigninResponse.config;
							int push = config.push;
							if (push == 1) {
								editor.putBoolean("push", true);
							} else {
								editor.putBoolean("push", false);
							}
							editor.putBoolean("isLogin", true);
							editor.putString("user", user.toJson().toString());
							editor.putInt("uid", usersigninResponse.user.id);
							editor.putString("sid", usersigninResponse.sid);
							editor.putString("nickename", user.nickname);
							editor.commit();
							SESSION.getInstance().uid = usersigninResponse.user.id;
							SESSION.getInstance().sid = usersigninResponse.sid;
							// //推送更新
							// PushModel pushModel = new PushModel(context);
							// pushModel.update();

							// 回调到登录界面
							UserModel.this.OnMessageResponse(url, jo, status);
						} else {
							if (usersigninResponse.error_code == APIErrorCode.MOBILE_NOT_EXIST
									|| usersigninResponse.error_code == APIErrorCode.ERROR_PASSWORD) {
								UserModel.this.OnMessageResponse(url, jo,
										status);
							} else {
								UserModel.this.callback(url,
										usersigninResponse.error_code,
										usersigninResponse.error_desc);
							}

						}

					}

				} catch (JSONException e) {

				}
				;
			}
		};
		Map<String, String> params = new HashMap<String, String>();
		try {
			params.put("json", request.toJson().toString());
		} catch (JSONException e) {

		}
		// 参数(json类型)和接口
		cb.url(ApiInterface.USER_SIGNIN).type(JSONObject.class).params(params);
		// 提交参数，并且访问服务器
		ajaxProgress(cb);
	}
	
	
/**
 * 普通用户登录
 * @param mobile
 * @param password
 */
	public void login(String mobile, String password) {

		usersigninRequest request = new usersigninRequest();
		request.mobile_phone = mobile;
		request.password = password;
		request.UUID = O2OMobile.getDeviceId(context);
		request.platform = "android";
		request.role = "2";
		request.ver = O2OMobileAppConst.VERSION_CODE;
		LOCATION location = new LOCATION();
		location.lat = LocationManager.getLatitude();
		location.lon = LocationManager.getLongitude();
		request.location = location;
		BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() {
			@Override
			public void callback(String url, JSONObject jo, AjaxStatus status) {

				// 获得网络的json数据之后，的回调函数
				try {
					UserModel.this.callback(this, url, jo, status);

					if (null != jo) {
						// 用户成功登录之后，返回的数据，转换为usersigninResponse对象
						usersigninResponse usersigninResponse = new usersigninResponse();
						usersigninResponse.fromJson(jo);
						if (usersigninResponse.succeed == 1) {
							// 保存返回来的数据
							USER user = usersigninResponse.user;
							CONFIG config = usersigninResponse.config;
							int push = config.push;
							if (push == 1) {
								editor.putBoolean("push", true);
							} else {
								editor.putBoolean("push", false);
							}
							editor.putBoolean("isLogin", true);
							editor.putString("user", user.toJson().toString());
							editor.putInt("uid", usersigninResponse.user.id);
							editor.putString("sid", usersigninResponse.sid);
							editor.putString("nickename", user.nickname);
							editor.commit();
							SESSION.getInstance().uid = usersigninResponse.user.id;
							SESSION.getInstance().sid = usersigninResponse.sid;
							// //推送更新
							// PushModel pushModel = new PushModel(context);
							// pushModel.update();

							// 回调到登录界面
							UserModel.this.OnMessageResponse(url, jo, status);
						} else {
							if (usersigninResponse.error_code == APIErrorCode.MOBILE_NOT_EXIST
									|| usersigninResponse.error_code == APIErrorCode.ERROR_PASSWORD) {
								UserModel.this.OnMessageResponse(url, jo,
										status);
							} else {
								UserModel.this.callback(url,
										usersigninResponse.error_code,
										usersigninResponse.error_desc);
							}

						}

					}

				} catch (JSONException e) {

				}
				;
			}
		};
		Map<String, String> params = new HashMap<String, String>();
		try {
			params.put("json", request.toJson().toString());
		} catch (JSONException e) {

		}
		// 参数(json类型)和接口
		cb.url(ApiInterface.USER_SIGNIN).type(JSONObject.class).params(params);
		// 提交参数，并且访问服务器
		ajaxProgress(cb);
	}

	// 新增修改手机号的功能
	public void changeMobile(String mobile) {
		userchange_profileRequest request = new userchange_profileRequest();
		request.mobile = mobile;
		request.sid = SESSION.getInstance().sid;
		request.uid = SESSION.getInstance().uid;
		request.ver = O2OMobileAppConst.VERSION_CODE;
		BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() {
			@Override
			public void callback(String url, JSONObject jo, AjaxStatus status) {
				try {
					UserModel.this.callback(this, url, jo, status);
					if (null != jo) {
						userchange_profileResponse response = new userchange_profileResponse();
						response.fromJson(jo);
						if (response.succeed == 1) {
							USER user = response.user;
							editor.putString("user", user.toJson().toString());
							editor.commit();
							UserModel.this.OnMessageResponse(url, jo, status);
						} else {
							UserModel.this.callback(url, response.error_code,
									response.error_desc);
						}
					}

				} catch (JSONException e) {

				}
				;
			}
		};
		Map<String, String> params = new HashMap<String, String>();
		try {
			params.put("json", request.toJson().toString());
		} catch (JSONException e) {

		}

		cb.url(ApiInterface.USER_CHANGE_PROFILE).type(JSONObject.class)
				.params(params);
		ajaxProgress(cb);
	}

	public void getVerifyCode(String mobile) {
		userverifycodeRequest request = new userverifycodeRequest();
		request.mobile_phone = mobile;
		request.ver = O2OMobileAppConst.VERSION_CODE;
		BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() {
			@Override
			public void callback(String url, JSONObject jo, AjaxStatus status) {
				try {
					UserModel.this.callback(this, url, jo, status);

					if (null != jo) {
						userverifycodeResponse response = new userverifycodeResponse();
						response.fromJson(jo);
						if (response.succeed == 1) {
							UserModel.this.OnMessageResponse(url, jo, status);
						} else {
							UserModel.this.callback(url, response.error_code,
									response.error_desc);
							if (response.error_code == APIErrorCode.MOBILE_EXIST) {
								UserModel.this.OnMessageResponse(url, jo,
										status);
							}
						}
					}

				} catch (JSONException e) {

				}
				;
			}
		};
		Map<String, String> params = new HashMap<String, String>();
		try {
			params.put("json", request.toJson().toString());
		} catch (JSONException e) {

		}

		cb.url(ApiInterface.USER_VERIFYCODE).type(JSONObject.class)
				.params(params);
		ajaxProgress(cb);

	}

	public void valid_verifycode(String mobile, String verifycode) {
		uservalidcodeRequest request = new uservalidcodeRequest();
		request.mobile_phone = mobile;
		request.verify_code = verifycode;
		request.ver = O2OMobileAppConst.VERSION_CODE;
		BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() {
			@Override
			public void callback(String url, JSONObject jo, AjaxStatus status) {
				try {
					UserModel.this.callback(this, url, jo, status);
					if (null != jo) {
						uservalidcodeResponse response = new uservalidcodeResponse();
						response.fromJson(jo);
						if (response.succeed == 1) {
							UserModel.this.OnMessageResponse(url, jo, status);
						} else {
							UserModel.this.callback(url, response.error_code,
									response.error_desc);
						}
					}

				} catch (JSONException e) {

				}
				;
			}
		};
		Map<String, String> params = new HashMap<String, String>();
		try {
			params.put("json", request.toJson().toString());
		} catch (JSONException e) {

		}

		cb.url(ApiInterface.USER_VALIDCODE).type(JSONObject.class)
				.params(params);
		ajaxProgress(cb);

	}

	public void signup(String mobile, String password, String nickname) {
		usersignupRequest request = new usersignupRequest();
		request.mobile_phone = mobile;
		request.nickname = nickname;
		request.invite_code = "";
		request.password = password;
		request.platform = "android";
		request.ver = O2OMobileAppConst.VERSION_CODE;
		LOCATION location = new LOCATION();
		location.lat = LocationManager.getLatitude();
		location.lon = LocationManager.getLongitude();
		request.location = location;
		BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() {
			@Override
			public void callback(String url, JSONObject jo, AjaxStatus status) {
				try {
					UserModel.this.callback(this, url, jo, status);

					if (null != jo) {
						usersignupResponse response = new usersignupResponse();
						response.fromJson(jo);
						if (response.succeed == 1) {
							USER user = response.user;
							CONFIG config = response.config;
							int push = config.push;
							if (push == 1) {
								editor.putBoolean("push", true);
							} else {
								editor.putBoolean("push", false);
							}
							editor.putBoolean("isLogin", true);
							editor.putString("user", user.toJson().toString());
							editor.putInt("uid", response.user.id);
							editor.putString("sid", response.sid);
							editor.commit();
							SESSION.getInstance().uid = response.user.id;
							SESSION.getInstance().sid = response.sid;
							UserModel.this.OnMessageResponse(url, jo, status);
						} else {
							if (response.error_code == APIErrorCode.NICKNAME_EXIST) {

								UserModel.this.OnMessageResponse(url, jo,
										status);
							}
							UserModel.this.callback(url, response.error_code,
									response.error_desc);
						}
					}

				} catch (JSONException e) {

				}
				;
			}
		};
		Map<String, String> params = new HashMap<String, String>();
		try {
			params.put("json", request.toJson().toString());
		} catch (JSONException e) {

		}

		cb.url(ApiInterface.USER_SIGNUP).type(JSONObject.class).params(params);
		// aq.ajax(cb);
		ajaxProgress(cb);
	}

	public void changeNickname(String nickname) {
		userchange_profileRequest request = new userchange_profileRequest();
		request.nickname = nickname;
		request.sid = SESSION.getInstance().sid;
		request.uid = SESSION.getInstance().uid;
		request.ver = O2OMobileAppConst.VERSION_CODE;
		BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() {
			@Override
			public void callback(String url, JSONObject jo, AjaxStatus status) {
				try {
					UserModel.this.callback(this, url, jo, status);
					if (null != jo) {
						userchange_profileResponse response = new userchange_profileResponse();
						response.fromJson(jo);
						if (response.succeed == 1) {
							USER user = response.user;
							editor.putString("user", user.toJson().toString());
							editor.commit();
							UserModel.this.OnMessageResponse(url, jo, status);
						} else {
							UserModel.this.callback(url, response.error_code,
									response.error_desc);
						}
					}

				} catch (JSONException e) {

				}
				;
			}
		};
		Map<String, String> params = new HashMap<String, String>();
		try {
			params.put("json", request.toJson().toString());
		} catch (JSONException e) {

		}

		cb.url(ApiInterface.USER_CHANGE_PROFILE).type(JSONObject.class)
				.params(params);
		ajaxProgress(cb);
	}

	public void changeSignature(String signture) {
		userchange_profileRequest request = new userchange_profileRequest();
		request.signature = signture;
		request.sid = SESSION.getInstance().sid;
		request.uid = SESSION.getInstance().uid;
		request.ver = O2OMobileAppConst.VERSION_CODE;
		BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() {
			@Override
			public void callback(String url, JSONObject jo, AjaxStatus status) {
				try {
					UserModel.this.callback(this, url, jo, status);
					if (null != jo) {
						userchange_profileResponse response = new userchange_profileResponse();
						response.fromJson(jo);
						if (response.succeed == 1) {
							USER user = response.user;
							;
							editor.putString("user", user.toJson().toString());
							editor.commit();
							UserModel.this.OnMessageResponse(url, jo, status);
						} else {
							UserModel.this.callback(url, response.error_code,
									response.error_desc);
						}
					}

				} catch (JSONException e) {

				}
				;
			}
		};
		Map<String, String> params = new HashMap<String, String>();
		try {
			params.put("json", request.toJson().toString());
		} catch (JSONException e) {

		}

		cb.url(ApiInterface.USER_CHANGE_PROFILE).type(JSONObject.class)
				.params(params);
		ajaxProgress(cb);
	}

	public void changeBrief(String brief) {
		userchange_profileRequest request = new userchange_profileRequest();
		request.brief = brief;
		request.sid = SESSION.getInstance().sid;
		request.uid = SESSION.getInstance().uid;
		request.ver = O2OMobileAppConst.VERSION_CODE;
		BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() {
			@Override
			public void callback(String url, JSONObject jo, AjaxStatus status) {
				try {
					UserModel.this.callback(this, url, jo, status);
					if (null != jo) {
						userchange_profileResponse response = new userchange_profileResponse();
						response.fromJson(jo);
						if (response.succeed == 1) {
							USER user = response.user;
							;
							editor.putString("user", user.toJson().toString());
							editor.commit();
							UserModel.this.OnMessageResponse(url, jo, status);
						} else {
							UserModel.this.callback(url, response.error_code,
									response.error_desc);
						}
					}

				} catch (JSONException e) {

				}
				;
			}
		};
		Map<String, String> params = new HashMap<String, String>();
		try {
			params.put("json", request.toJson().toString());
		} catch (JSONException e) {

		}

		cb.url(ApiInterface.USER_CHANGE_PROFILE).type(JSONObject.class)
				.params(params);
		ajaxProgress(cb);
	}

	public void changePassword(String oldPassword, String newPassword) {
		userchange_passwordRequest request = new userchange_passwordRequest();
		request.old_password = oldPassword;
		request.new_password = newPassword;
		request.sid = SESSION.getInstance().sid;
		request.uid = SESSION.getInstance().uid;
		request.ver = O2OMobileAppConst.VERSION_CODE;
		BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() {
			@Override
			public void callback(String url, JSONObject jo, AjaxStatus status) {
				try {
					UserModel.this.callback(this, url, jo, status);
					if (null != jo) {
						userchange_passwordResponse response = new userchange_passwordResponse();
						response.fromJson(jo);
						if (response.succeed == 1) {
							UserModel.this.OnMessageResponse(url, jo, status);
						} else {
							if (response.error_code == APIErrorCode.ERROR_PASSWORD) {
								UserModel.this.OnMessageResponse(url, jo,
										status);
							}
							UserModel.this.callback(url, response.error_code,
									response.error_desc);
						}
					}

				} catch (JSONException e) {

				}
				;
			}
		};
		Map<String, String> params = new HashMap<String, String>();
		try {
			params.put("json", request.toJson().toString());
		} catch (JSONException e) {

		}

		cb.url(ApiInterface.USER_CHANGE_PASSWORD).type(JSONObject.class)
				.params(params);
		ajaxProgress(cb);
	}

	// 检查验证码是否存在
	public void checkInviteCode(String inviteCode) {
		userinvite_codeRequest request = new userinvite_codeRequest();
		request.sid = SESSION.getInstance().sid;
		request.uid = SESSION.getInstance().uid;
		request.invitecode = inviteCode;
		request.ver = O2OMobileAppConst.VERSION_CODE;//
		BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() {
			@Override
			public void callback(String url, JSONObject jo, AjaxStatus status) {
				try {
					UserModel.this.callback(this, url, jo, status);
					if (null != jo) {
						userinvite_codeResponse response = new userinvite_codeResponse();
						response.fromJson(jo);
						if (response.succeed == 1) {
							UserModel.this.OnMessageResponse(url, jo, status);
						} else {
							UserModel.this.callback(url, response.error_code,
									response.error_desc);
						}
					}

				} catch (JSONException e) {

				}
				;
			}
		};
		Map<String, String> params = new HashMap<String, String>();
		try {
			params.put("json", request.toJson().toString());
		} catch (JSONException e) {

		}

		cb.url(ApiInterface.USER_INVITE_CHECK).type(JSONObject.class)
				.params(params);
		ajaxProgress(cb);
	}

	// 获取验证码
	public void getInviteCode() {
		userinvite_codeRequest request = new userinvite_codeRequest();
		request.sid = SESSION.getInstance().sid;
		request.uid = SESSION.getInstance().uid;
		request.ver = O2OMobileAppConst.VERSION_CODE;
		BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() {
			@Override
			public void callback(String url, JSONObject jo, AjaxStatus status) {
				try {
					UserModel.this.callback(this, url, jo, status);
					if (null != jo) {
						userinvite_codeResponse response = new userinvite_codeResponse();
						response.fromJson(jo);
						if (response.succeed == 1) {
							invite_code = response.invite_code;
							text=response.text;
							editor.putString(
									"invitecode_" + SESSION.getInstance().uid,
									invite_code);
							editor.commit();
							UserModel.this.OnMessageResponse(url, jo, status);
						} else {
							UserModel.this.callback(url, response.error_code,
									response.error_desc);
						}
					}

				} catch (JSONException e) {

				}
				;
			}
		};
		Map<String, String> params = new HashMap<String, String>();
		try {
			params.put("json", request.toJson().toString());
		} catch (JSONException e) {

		}

		cb.url(ApiInterface.USER_INVITE_CODE).type(JSONObject.class)
				.params(params);
		ajaxProgress(cb);
	}

	// 申请成为自由人
	public void certify(String name, String identity, ENUM_USER_GENDER gender,
			File avatar, String mobile, String password, String invite,
			File vetify_avatar, String motoid) {
		// usercertifyRequest request = new usercertifyRequest();

		usersignupRequest request = new usersignupRequest();
		request.mobile_phone = mobile;
		request.nickname = name;
		request.invite_code = invite;
		request.password = password;
		// request.moto_id = moto_id;
		request.platform = "android";
		LOCATION location = new LOCATION();
		location.name = LocationManager.getLocaname();
		location.lat = LocationManager.getLatitude();
		location.lon = LocationManager.getLongitude();
		request.location = location;
		request.identity_card = identity;
		request.gender = gender.value();
		request.ver = O2OMobileAppConst.VERSION_CODE;
		request.moto_id = motoid;
		BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() {
			@Override
			public void callback(String url, JSONObject jo, AjaxStatus status) {
				try {
					UserModel.this.callback(this, url, jo, status);
					if (null != jo) {
						usersignupResponse response = new usersignupResponse();
						response.fromJson(jo);
						if (response.succeed == 1) {
							UserModel.this.OnMessageResponse(url, jo, status);
						} else {
							UserModel.this.callback(url, response.error_code,
									response.error_desc);
						}
					}

				} catch (JSONException e) {

				}
				;
			}
		};
		Map<String, Object> params = new HashMap<String, Object>();
		try {
		
			params.put("json", request.toJson().toString());
			if (null != avatar) {
				params.put("avatar", avatar);
			}
			if (null != vetify_avatar) {
				params.put("vetify_avatar", vetify_avatar);
			}

		} catch (JSONException e) {

		}

		cb.url(ApiInterface.USER_CERTIFY).type(JSONObject.class).params(params);
		ajaxProgress(cb);
	}

	// 修改性别
	public void changeGender(ENUM_USER_GENDER gender) {
		userchange_profileRequest request = new userchange_profileRequest();
		request.gender = gender.value();
		request.sid = SESSION.getInstance().sid;
		request.uid = SESSION.getInstance().uid;
		request.ver = O2OMobileAppConst.VERSION_CODE;
		BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() {
			@Override
			public void callback(String url, JSONObject jo, AjaxStatus status) {
				try {
					UserModel.this.callback(this, url, jo, status);
					if (null != jo) {
						userchange_profileResponse response = new userchange_profileResponse();
						response.fromJson(jo);
						if (response.succeed == 1) {
							USER user = response.user;
							editor.putString("user", user.toJson().toString());
							editor.commit();
							UserModel.this.OnMessageResponse(url, jo, status);
						} else {
							UserModel.this.callback(url, response.error_code,
									response.error_desc);
						}
					}

				} catch (JSONException e) {

				}
				;
			}
		};
		Map<String, String> params = new HashMap<String, String>();
		try {
			params.put("json", request.toJson().toString());
		} catch (JSONException e) {

		}

		cb.url(ApiInterface.USER_CHANGE_PROFILE).type(JSONObject.class)
				.params(params);
		ajaxProgress(cb);
	}

}
